{% extends "base.html" %}
{% load staticfiles %}

{% block page_content %}
<section class="content-header" style="padding-top:0px" xmlns="http://www.w3.org/1999/html">
<div class="row">
    <div class="box box-info">
        <div class="box-header">
            <h2>List of videos & datasets</h2>
            {% if is_paginated %}
                <div class="pagination text-center" style="width:100%">
                    <span class="page-links">
                        {% if page_obj.has_previous %}
                            <a class="btn btn-info" style="float:left" href=".?page={{ page_obj.previous_page_number }}"><i class="fa fa-backward"></i>  Go back</a>
                        {% endif %}
                        <span class="page-current " style="font-size:24pt;font-weight:bold">
                            {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
                        </span>
                        {% if page_obj.has_next %}
                            <a class="btn btn-info" style="float:right" href=".?page={{ page_obj.next_page_number }}">Load more  <i class="fa fa-forward"></i></a>
                        {% endif %}
                    </span>
                </div>
            {% endif %}
        </div>
    </div>
</div>
</section>
<section class="content">
<div class="row">
    <div class="col-lg-12 col-md-12">
        <div class="box">
            <div class="box-body">
                <table class="table dataTables">
                <thead>
                <tr>
                    <th class="text-center">type</th>
                    <th class="text-center">name</th>
                    <th class="text-center">duration</th>
                    <th class="text-center">frames</th>
                    <th class="text-center">segments</th>
                    <th class="text-center">height</th>
                    <th class="text-center">width</th>
                    <th class="text-center">created</th>
                    <th class="text-center">youtube</th>
                    <th class="text-center">view</th>
                </tr>
                </thead>
                <tbody>
                {% for v in video_list %}
                {% if not v.query %}
                    <tr>
                        <td>{%  if v.dataset and v.query %} Query {% elif v.dataset %} Dataset {% else %}Video {% endif %}</td>
                        <td>{{ v.name }} </td>
                        <td class="text-right">{{ v.length_in_seconds }} </td>
                        <td class="text-right">{{ v.frames }} </td>
                        <td class="text-right">{{ v.segments }} </td>
                        <td class="text-right">{{ v.height }} </td>
                        <td class="text-right">{{ v.width }} </td>
                        <td class="text-center">{{ v.created }}</td>
                        <td class="text-center">{% if v.youtube_video %}<a href="{{ v.url }}" target="_blank">youtube link</a>{% endif %}</td>
                        <td class="text-center"><a  href="/videos/{{ v.pk }}">view</a></td>
                    </tr>
                    {% endif %}
                {% endfor %}
                </tbody>
                </table>
            </div>
        </div>
            <div class="box box-primary" >
                <div class="box-header with-border">
                    <h3>Exports</h3>
                </div>
                <div class="box-body">
                    <table class="table dataTables-dict">
                        <thead>
                            <tr>
                                <th class="text-center">Video</th>
                                <th class="text-center">Started</th>
                                <th class="text-center">Completed</th>
                                <th class="text-center">Download URL or S3 region/bucket/key</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for e in exports %}
                            <tr>
                                <td>{{ e.video.name }}</td>
                                <td>{{ e.started }}</td>
                                <td class="text-center">{{ e.completed }}</td>
                                <td class="text-center">
                                    {% if e.arguments.file_name %}
                                        <a href="{{ MEDIA_URL }}exports/{{ e.arguments.file_name }}">click to download</a>
                                    {% elif e.completed %}
                                        s3://{{ e.arguments.bucket }}/{{ e.arugments.key }}
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
    </div>
</div>
</section>
{% endblock %}
{% block page_js%}
<script>
    $(document).ready(function() {
        InitializeTables();
    })
</script>
{% endblock %}
